package com.example.learn.hwod.背包代码;

public class 标准背包 {
    public static void main(String[] args) {
        int[] weights={2,3,4,5};
        int[] values={3,4,5,6};
        int capacity=5;
        int n = weights.length;

        int[] dp = new int[capacity + 1];
        for (int i = 0; i < n; i++) {
            for (int j = capacity; j >=weights[i] ; j--) {
                dp[j] = Math.max(dp[j], dp[j-weights[i]] + values[i]);
            }
        }
        System.out.println("最大值为："+dp[capacity]);
    }
}
